/**  
  -- The Performance Driven Lime Project -- 

  A self adaptive tuple space for mobile agents and hosts by dynamic
  adapting tuple's replication policy.
  
  Copyright (C) 2008
  Xing Jiankuan, Pan Wenhui
  SAGroup of Tsinghua University

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
package sagroup.dracots;

import sagroup.dracots.TupleType;
import lime2.LimeTupleSpace;
import lime2.Location;
import lime2.TupleID;

/**
 * A signal tuple is used for transfer message between two agents (either on two
 * hosts or the same host). No replication is support for this kind of tuple. No
 * additional fields are added in this class to keep its generality.
 * 
 * @author Xing Jiankuan
 * 
 */
public class SignalTuple extends DracoTuple {

	/**
	 * The source location that send this CommandTuple
	 */
	@sagroup.dracots.Field
	protected Location src;

	public SignalTuple() {

	}

	private SignalTuple(TupleID tid, Location curr, Location dest,
			TupleType type, TupleID vid, Location src) {
		super(tid, curr, dest, type, vid);
		this.src = src;
	}
	
	public SignalTuple(TupleType type, Location dest) {
		this(LimeTupleSpace.nextTID(), Location.HERE, dest, type, DracoTS.nextVID(), Location.HERE);
	}

	public SignalTuple(TupleID tid, Location curr, Location dest,
			TupleType type, TupleID vid) {
		this(tid, curr, dest, type, vid, Location.HERE);
	}
	
	/**
	 * Create a template matching a signal tuple with specified tuple type
	 * 
	 * @param type
	 *            
	 * @return the constructed SignalTuple instance
	 * @author Huang Xiaodong
	 */
	public static SignalTuple createTypeTemplate(TupleType type) {
		SignalTuple t = new SignalTuple(null, Location.UNSPECIFIED, Location.UNSPECIFIED,
				type, null, null);
		t.setMatchAll(true);
		return t;
	}
	
	/**
	 * Create a template matching a signal tuple with specified tuple type
	 * which is local.
	 * @param type
	 * @return
	 * @author Xing Jiankuan
	 */
	public static SignalTuple createLocalTypeTemplate(TupleType type) {
		SignalTuple t = new SignalTuple(null, Location.HERE, Location.HERE,
				type, null, null);
		t.setMatchAll(true);
		return t;
	}

	public Location getSrc() {
		return src;
	}

	public String toString() {
		return super.toString() + ";src=" + src;
	}

	private static final long serialVersionUID = 7153411337437406060L;	

}
